<?php

/*
 * Augabe der Aktoren Seiten
 */

function print_pages_light() {
	// Holen der globalen Variablen
	global $version, $theme_popup, $theme_data, $theme_overlay, $config_xml;

	$actoren_tab = array();
	$actor_tab = array();
	$current_page_num = -1;
	$count_page = -1;
	// Aufruf von array_multisort() mit dem Array, das sortiert werden soll und den entsprechenden Flags
	//9 array_multisort($array['id'], $array['rasse'], $array['tier_id']);
	//Einlesen aller Aktoren in array  |Page|SortID|Actor|

	$path = "/config/Actors/Actor";
	if (!$res = $config_xml -> xpath($path)) {
		echo "keine Actoren vorhanden!";
	} else {

		foreach ($res as $actor) {
			//	var_dump($actor);

			$Page = $actor -> $version;
			$ActorID = $actor['ID'];
			$path = $version;
			$Page_XML = $actor -> xpath($path);
			$SortID = $Page_XML[0]['sortID'];

			//	$SortID = $Page_XML['sortID'];
			$actoren_tab[] = array('Page' => (STRING)$Page, 'sortID' => (STRING)$SortID, 'ActorID' => (STRING)$ActorID);
		}

	}
	// Sortieren der Aktoren

	# get a list of sort columns and their data to pass to array_multisort
	$sort = array();
	foreach ($actoren_tab as $key => $row) {
		$PageColumn[$key] = $row['Page'];
		$SortColumn[$key] = $row['sortID'];
	}
	# sort by event_type desc and then title asc
	array_multisort($PageColumn, SORT_ASC, $SortColumn, SORT_ASC, $actoren_tab);

	// Nur wenn Aktoren vorhanden, dann auch weitermachen
	foreach ($actoren_tab as $actoren_tab_line) {

		if ($current_page_num != $actoren_tab_line['Page']) {
			if ($current_page_num != -1) {
				echo "
					</table>
				</div>				<br><br><br><br><br><br>
			</div>
			";
				print_footer_light("actors", $count_page, FALSE);
				print_page_end();
			};
			$count_page = $count_page + 1;
			print_page_start('actors', $count_page);

			print_menu_popup($count_page);
			print_header_light('Aktoren');
			print_page_header($theme_data);
			$current_page_num = $actoren_tab_line['Page'];

			// Inhalt pro Seite
			echo "
				<div data-role=content $theme_data>	
					<table width='100%' border='0' cellpadding='0' cellspacing='0'>
						<tr>
							<td width='30%'></td>
							<td width='35%'></td>
							<td width='35%'></td>
						</tr>					";

		}
		print_actor_table_line($actoren_tab_line['ActorID']);
	}
	//Sortieren der Aktoren
	echo "
					</table>
				</div>
				<br><br><br><br><br><br>
			</div>
			";
	print_footer_light("actors", $count_page, TRUE);
	print_page_end();
}

// Zeile für Aktorentabelle ausgeben
function print_actor_table_line($actor) {
	
	static $numSlider = 0;
	// Infos zu Aktor lesen
	
	global $config_xml;
	$path = '/config/Actors/Actor[@ID=\''. $actor.'\']';
	$actor_xml = $config_xml->xpath($path);
	$text = $actor_xml[0]->Name;
		
	echo "
						<tr>
						<td>$text</td>
						<td colspan='2' align='left'>
						<div class=ui-corner-all ui-controlgroup ui-controlgroup-horizontal data-role=controlgroup data-type=horizontal>
							<div class=ui-controlgroup-controls>
								<div data-role=controlgroup data-type=horizontal>

									<a href=# onClick=\"perform_light_change('$actor', 'ON', 0)\" data-role=button id=on data-icon=custom>ON</a>
									<a href=# onClick=\"perform_light_change('$actor', 'OFF', 0)\" data-role=button id=off data-icon=custom>OFF</a>

								</div>

							</div>
						</div></td>
					</tr>";
	if (isDimmer($actor_xml[0])){
		echo"
					<tr>
						<td colspan='3'>
							<table width='100%'>
								<tr>
									<td width='10%'><a href=# onClick=\"perform_light_change('$actor', 'DARK', 0)\" data-role='button' data-icon='minus' data-iconpos='notext'>Minus</a></td>
									<td width='80%'><input type='range' id='Actors_Slider$numSlider' value='6' min='0' max='16' /></td>
									<td width='10%'><a href=# onClick=\"perform_light_change('$actor', 'BRIGHT', 0)\" data-role='button' data-icon='plus' data-iconpos='notext' >Plus</a></td>
								</tr>
							</table>
						</td>

					</tr>
	";
	$numSlider++;
	}
}
?>

